unit uUSBRelayDevice;

interface

const
  UsbRelayDevice = 'usb_relay_device.dll';

type
  TUsbRelayDeviceType = (urdOneChannel = 1, urdTwoChannel = 2, urdFourChannel = 4, urdEightChannel = 8);

  PUsbRelayDeviceInfo = ^TUsbRelayDeviceInfo;
  TUsbRelayDeviceInfo = record
    SerialNumber: PByte;
    DevicePath: PShortInt;
    UsbRelayDeviceType: TUsbRelayDeviceType;
    Next: PUsbRelayDeviceInfo;
  end;


  {
    init the USB Relay Libary
    @returns: This function returns 0 on success and -1 on error.
	}
  function usb_relay_init: Integer; cdecl; external UsbRelayDevice;

  {
    Finalize the USB Relay Libary.
    This function frees all of the static data associated with
    USB Relay Libary. It should be called at the end of execution to avoid
    memory leaks.
    @returns:This function returns 0 on success and -1 on error.
	}
  function usb_relay_exit: Integer; cdecl; external UsbRelayDevice;

  {Enumerate the USB Relay Devices.}
	function usb_relay_device_enumerate: PUsbRelayDeviceInfo; cdecl; external UsbRelayDevice;

  {Free an enumeration Linked List}
	procedure usb_relay_device_free_enumerate(pUsbRelayDeviceInfo: PUsbRelayDeviceInfo); cdecl; external UsbRelayDevice;

  {open device that serial number is serial_number
    @return: This funcation returns a valid handle to the device on success or NULL on failure.
    e.g: usb_relay_device_open_with_serial_number("abcde", 5") }
	function usb_relay_device_open_with_serial_number(const serial_number: PByte; len: Word): Integer; cdecl;
    external UsbRelayDevice;

	{open a usb relay device
	  @return: This funcation returns a valid handle to the device on success or NULL on failure.
	}
	function usb_relay_device_open(device_info: PUsbRelayDeviceInfo): Integer; cdecl; external UsbRelayDevice;

	{close a usb relay device}
	procedure usb_relay_device_close(hHandle: Cardinal); cdecl; external UsbRelayDevice;

	{open a relay channel on the USB-Relay-Device
	@paramter: index -- which channel your want to open
	hHandle -- which usb relay device your want to operate
	@returns: 0 -- success; 1 -- error; 2 -- index is outnumber the number of the usb relay device
	}
	function usb_relay_device_open_one_relay_channel(hHandle: Cardinal; index: Integer): Integer; cdecl;
    external UsbRelayDevice;

	{open all relay channel on the USB-Relay-Device
	@paramter: hHandle -- which usb relay device your want to operate
	@returns: 0 -- success; 1 -- error
	}
	function usb_relay_device_open_all_relay_channel(hHandle: Cardinal): Integer; cdecl; external UsbRelayDevice;

	{close a relay channel on the USB-Relay-Device
	@paramter: index -- which channel your want to close
	hHandle -- which usb relay device your want to operate
	@returns: 0 -- success; 1 -- error; 2 -- index is outnumber the number of the usb relay device
	}
	function usb_relay_device_close_one_relay_channel(hHandle: Cardinal; index: Integer): Integer; cdecl; external UsbRelayDevice;

	{close all relay channel on the USB-Relay-Device
	@paramter: hHandle -- which usb relay device your want to operate
	@returns: 0 -- success; 1 -- error
	}
	function usb_relay_device_close_all_relay_channel(hHandle: Cardinal): Integer; cdecl; external UsbRelayDevice;

	{
	status bit: High --> Low 0000 0000 0000 0000 0000 0000 0000 0000, one bit indicate a relay status.
	the lowest bit 0 indicate relay one status, 1 -- means open status, 0 -- means closed status.
	bit 0/1/2/3/4/5/6/7/8 indicate relay 1/2/3/4/5/6/7/8 status
	@returns: 0 -- success; 1 -- error
	}
	function usb_relay_device_get_status(hHandle: Cardinal; status: PInteger): Integer; cdecl; external UsbRelayDevice;


implementation

end.
